Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
Why does template.content only show "#document-fragment" in the console?

I'm happy I've gotten this far. I can grab a template, modify it, then append it to my document. But, why don't I see the entire HTML structure in the console when I try to output my <template>?

Conceptually, I understand I'm dealing with a document fragment in some capacity... Still, my expectation was to see the fragment's structure:

enter image description here

My Templates:


function basicModal() {
    
    const template = document.createElement('template');
    template.innerHTML = `
    <div id="someModal" class="modal" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Modal title</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <p>Modal body text goes here.</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary">Save changes</button>
            </div>
            </div>
        </div>
    </div>`;

    console.log('--basic modal template', template)
    console.log('--basic modal template content', template.content)

    return template.content;

}


export { basicModal };

Modal Handler

import { basicModal } from './templates.js';

function renderRetireeForm() {

    const myTemplate = basicModal();
    console.log('--myTemplate', myTemplate)
    
    myTemplate.querySelector('.modal').setAttribute('id', 'zzzModal')

    document.body.appendChild(myTemplate);

    // i open it later

}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!